package game_core

import "go_server/zinx/zlog"

type Map struct {
	GridMap map[uint16]*Grid
	XCount int32
	ZCount int32
}

func NewMap(size int32, xCount int32, zCount int32) *Map {
	indexMap := &Map{
		GridMap: make(map[uint16]*Grid, size),
		XCount: xCount,
		ZCount: zCount,
	}
	return indexMap
}

func (m *Map) GetGridByKey(minx, minz int32) (*Grid, bool) {
	key := uint16(minx)*100 + uint16(minz)
	grid, ok := m.GridMap[key]
	if !ok {
		return nil, false
	} else {
		return grid, true
	}
}

func (m *Map) SetGridStatusByKey(minx, minz int32, status bool) bool {
	key := uint16(minx)*100 + uint16(minz)
	grid, ok := m.GridMap[key]
	if !ok {
		zlog.Errorf("SetGridStatusByKey err!!! 找不到对应的格子,minx: %d, minz: %d", minx, minz)
		return ok
	}
	grid.Used = status
	return ok
}
